#include"sort.h"

void TestInsertSort()
{
	int a[] = { 3,5,1,6,2,3,7,9,0,8,-3,-1,-7,-2,-5,-9 };
	PrintArray(a, sizeof(a) / sizeof(int));

	InsertSort(a, sizeof(a) / sizeof(int));

	PrintArray(a, sizeof(a) / sizeof(int));
}

void TestQuickSort()
{
	//int a[] = { 6,1,2,7,9,3,4,5,10,8 };
	int a[] = { 6,1,2,6,9,3,4,6,10,8 };
	PrintArray(a, sizeof(a) / sizeof(int));

	QuickSort(a, 0, sizeof(a) / sizeof(int) - 1);

	PrintArray(a, sizeof(a) / sizeof(int));
}

void TestMergeSort()
{
	//int a[] = { 6,1,2,7,9,3,4,5,10,8 };
	int a[] = { 6,1,2,6,9,3,4,6,10,8,10,11 };
	PrintArray(a, sizeof(a) / sizeof(int));

	MergeSort(a, sizeof(a) / sizeof(int));

	PrintArray(a, sizeof(a) / sizeof(int));
}

void TestMergeSortNonR()
{
	//int a[] = { 6,1,2,7,9,3,4,5,10,8 };
	int a[] = { 6,1,2,6,9,3,4,6,10,8,10,11 };
	PrintArray(a, sizeof(a) / sizeof(int));

	MergeSortNonR(a, sizeof(a) / sizeof(int));

	PrintArray(a, sizeof(a) / sizeof(int));
}

void TestOP()
{
	srand(time(0));
	const int N = 100000;
	int* a1 = (int*)malloc(sizeof(int) * N);
	int* a2 = (int*)malloc(sizeof(int) * N);
	int* a3 = (int*)malloc(sizeof(int) * N);
	
	if (a1 == NULL || a2 == NULL || a3 == NULL)
	{
		perror("malloc");
		return;
	}

	for (int i = 0; i < N; ++i)
	{
		a1[i] = rand();
		a2[i] = a1[i];
		a3[i] = a1[i];
	}

	int begin1 = clock();
	//InsertSort(a1, N);
	int end1 = clock();

	int begin2 = clock();
	QuickSort(a2, 0,N-1);
	int end2 = clock();

	int begin3 = clock();
	MergeSort(a3, N);
	int end3 = clock();


	printf("InsertSort:%d\n", end1 - begin1);
	printf("QuickSort:%d\n", end2 - begin2);
	printf("MergeSort:%d\n", end3 - begin3);

	free(a1);
	free(a2);
	free(a3);
}

int main()
{
	//TestInsertSort();
	//TestQuickSort();
	//TestMergeSort();
	//TestMergeSortNonR();
	TestOP();

	return 0;
}